//********************************************************************
// 
//  file:  MetaData.cs
// 
//  (C) Copyright 2010, Diomede Corporation
//  All rights reserved
// 
//  Use, modification, and distribution is subject to   
//  the New BSD License (See accompanying file license.txt).
// 
//********************************************************************

using System;
using System.Collections.Generic;
using System.Text;
using Diomede.SDK;

namespace data.diomedestorage.com
{
    public partial class MetaData
    {

        private ISession session;

        public ISession Session
        {
            get { return session; }
            set { session = value; }
        }

        public IUpdateMetaDataExecResult Update(string name, string value)
        {
            if (session == null)
            {
                return new UpdateMetaDataExecResult(new Exception("No binded session."));
            }
            try
            {
                this.name = name;
                this.value = value;
                session.ServiceClient.EditMetaData(session.Token, this.metaDataID, name, value);
                return new UpdateMetaDataExecResult("MetaData updated successfully.");
            }
            catch (Exception ex)
            {
                return new UpdateMetaDataExecResult(ex);
            }
        }

        public IDeleteMetaDataExecResult DeleteAllInstances()
        {
            if (session == null)
            {
                return new DeleteMetaDataExecResult(new Exception("No binded session."));
            }
            try
            {
                session.ServiceClient.DeleteMetaData(session.Token, metaDataID);
                return new DeleteMetaDataExecResult("Delete MetaData successful.");
            }
            catch (Exception ex)
            {
                return new DeleteMetaDataExecResult(ex);
            }
        }
    }
}
